package wiki.kaizen.cloud.shiro.stateless.properties;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;

/**
 * springboot 配置 参数列表
 * @author xeepoo
 * */
@Getter
@Setter
@ConfigurationProperties(prefix = "kaizen")
public class SecurityProperties {

    /**
    *缓存器前缀 配置
    * */
    private Prefix cachePrefix;

    /**
     * 求情头token名称
     * */
    public static String tokenHeaderName = "authorization";

    /**
    * token 签名加密算法
    * */
    private String tokenSignatureAlgorithm = "HS256";
    /**
    * 发行者
    * */
    private String issuer = "KAIZEN";
    /**
     * jwt加密秘钥
     * */
    private String secret = "wiki.kaizen" ;
    /**
     * token过期时间 默认1小时
     * */
    private Long expireTime = 3600000L;//

    /**
     * refreshToken过期时间 默认10小时
     * */
    public static Long refreshExpireTime = 36000000L;

    /**
     * session 有效性验证时间间隔
     * */
    private Long sessionValidationInterval = 1800000L;//

    /**
     * 是否开启鉴权缓存
     * */
    private Boolean enableCacheAuth= Boolean.FALSE;

    private AccessAccount account = new AccessAccount();
    private SecurityFilter securityFilter = new SecurityFilter();
    private Redis redis = new Redis();

    @Setter
    @Getter
    public static class Redis{

        /**
        * 激活的连接最少个数
        * */
        private Integer minIdle = 3;
        /**
        * 激活链接最多个数
        * */
        private Integer maxIdle = 20;
        /**
         * 链接等待时间
         * */
        private Long maxWaitMillis = 1000L;
        /**
         * 连接池数量
         * */
        private Integer maxTotal = 100;

        /**
        * 主机名
        * */
        private String host = "127.0.0.1";
        /**
        * 端口
        * */
        private Integer port = 6379;
        /**
         * 密码
         * */
        private String password="123456";

        /**
         * 超时时间
         * */
        private Integer timeout = 10000;

        /**
        * 连接池
        * */
        private  Short database = 0;
    }



    @Getter
    @Setter
    public static class AccessAccount{

        /**
         * 同一账号最多同时可登录数量
         * */
        private Integer max = 2;
        /**
         * 是否踢出后来登录的账号
         * */
        private Boolean kickoutAfter = Boolean.FALSE;
        /**
        * 提出后转到的地址
        * */
        private String kickoutUrl = "/kaizen/kickout";
        /**
         * 踢出设置的session attribute 的name
         * */
        private String kickoutName = "kickout" ;

        /**
         * 密码试错次数
         * */
        private Short tryMax = 5;

        /*
        * 加密算法
        * */
        private String hashAlgorithmName = "MD5";

        /**
         *循环次数
         */
        private Short hashIterations = 4;

    }

    @Getter
    @Setter
    public static class SecurityFilter{
        private String loginUrl="/kaizen/login";
        private String unauthorizedUrl="/kaizen/unauthorized";
        private String lockedUrl = "/kaizen/locked";
        private List<String> anons;
        private List<String> authcs;
    }

    @Setter
    @Getter
    public static class Prefix{
        public static String global= "security:";//全局缓存前缀
        /**
         * 身份验证缓存器
         * */
        public static String authentic = global+"authentic:";
        /*
         * 授权缓存器
         * */
        public static String authorize = global+"authorize:";
        /**
         * 登录个数限制缓存器
         * */
        public static String limit = global+"limit:";
        /**
         * 试错缓存器
         * */
        public static String tryFail = global+"tryFail:";
        /**
         * token缓存器
         * */
        public static String token = global+"token:";
    }
}
